import Home from "@/pages/Home";
import Login from "@/pages/Login";
import Register from "@/pages/Register";
import Search from "@/pages/Search";
import Detail from "@/pages/Detail";
import AddCartSuccess from "@/pages/AddCartSuccess";
import Shopcart from "@/pages/Shopcart";
import Trade from "@/pages/Trade";
import Pay from "@/pages/Pay";
import PaySuccess from "@/pages/PaySuccess";
import Center from "@/pages/Center";

//个人中心的二级路由组件
import MyOrder from '@/pages/Center/myOrder';
import TeamOrder from '@/pages/Center/teamOrder'

export default [
    {
        path: '/paySuccess',
        component: PaySuccess,
        meta: { show: true },
        beforeEnter: (to, from, next) => {
            if(from.path == '/pay'){
                next()
            } else {
                next(false)
            }
        }
    },
    {
        path: '/pay',
        component: Pay,
        meta: { show: true },
        beforeEnter: (to, from, next) => {
            if(from.path == '/trade'){
                next()
            } else {
                next(false)
            }
        }
    },
    {
        path: '/trade',
        component: Trade,
        meta: { show: true },
        // 路由独享守卫
        beforeEnter: (to, from, next) => {
            if(from.path == '/shopcart'){
                next()
            } else {
                next(false)
            }
        }
    },
    {
        path: '/shopcart',
        component: Shopcart,
        meta: { show: true },
    },
    {
        path: '/addCartSuccess',
        component: AddCartSuccess,
        meta: { show: true },
    },
    {
        path: '/detail/:skuId?',
        component: Detail,
        //路由元信息,控制当前路由是否需要Footer组件
        meta: { show: true },
    },
    {
        path: "/",
        redirect: '/home', //重定向到首页
        meta: {
            show: true
        }
    },
    {
        path: "/home",
        component: Home,
        meta: {
            show: true
        }
    },
    {
        path: "/login",
        component: Login,
        meta: {
            show: false
        }
    },
    {
        path: "/register",
        component: Register,
        meta: {
            show: false
        }
    },
    {
        path: "/search/:keyword?",  // 同时使用 query 和 params 参数
        // path: "/search",
        component: Search,
        meta: {
            show: true
        },
        name: 'search'
    },
    {
        path: '/center',
        component: Center,
        meta: { show: true },
        //二级路由配置的地方
        children: [
            //我的订单
            {
                path: 'myorder',
                component: MyOrder
            }
            ,
            {
                path: 'teamorder',
                component: TeamOrder
            }
            ,
            {
                path: '/center',
                redirect: '/center/myorder'
            }
        ]
    },
    {
        path: '/communication',
        component: () => import('@/pages/Communication/Communication'),
        children: [
            {
                path: 'event',
                component: () => import('@/pages/Communication/EventTest/EventTest'),
                meta: {
                    show: false
                },
            },
            {
                path: 'model',
                component: () => import('@/pages/Communication/ModelTest/ModelTest'),
                meta: {
                    show: false
                },
            },
            {
                path: 'sync',
                component: () => import('@/pages/Communication/SyncTest/SyncTest'),
                meta: {
                    show: false
                },
            },
            {
                path: 'attrs-listeners',
                component: () => import('@/pages/Communication/AttrsListenersTest/AttrsListenersTest'),
                meta: {
                    show: false
                },
            },
            {
                path: 'children-parent',
                component: () => import('@/pages/Communication/ChildrenParentTest/ChildrenParentTest'),
                meta: {
                    show: false
                },
            },
            {
                path: 'scope-slot',
                component: () => import('@/pages/Communication/ScopeSlotTest/ScopeSlotTest'),
                meta: {
                    show: false
                },
            }
        ],
    },
]
